﻿@using ERP.WebUI
@model SearchUserModel
@{
    ViewBag.Title = ViewBag.CurrentTitle;
    var changePwdButton = new ButtonModel();
    var editButton = new ButtonModel();
    var deleteButton = new ButtonModel();
    changePwdButton = ViewBag.ChangePwd;
    editButton = ViewBag.Edit;
    deleteButton = ViewBag.Delete;
    var createButton = new ButtonModel();
    createButton = ViewBag.Create;
}
@section css{
    @Styles.Render("~/bundles/css/jqueryui")
}

<div id="content-body" class="row-fluid">
    <div class="span22">
        <!--操作 -->
        <div class="widget-box">
            <div class="widget-title">
                <span class="icon"><i class="icon-search"></i></span>
                <h5>查询条件</h5>
            </div>
            <div class="widget-content nopadding">
                <form class="form-horizontal search-form" method="post" name="basic_validate" novalidate="novalidate">

                    <div class="control-group">
                        <div class="search-group">
                            <label class="search-label">@Html.DisplayNameFor(t => t.LoginName)</label>
                            <div class="span2 search-input">
                                @Html.TextBoxFor(t => t.LoginName)
                            </div>
                        </div>
                        <div class="search-group">
                            <label class="search-label">@Html.DisplayNameFor(t => t.FullName)</label>
                            <div class="span2 search-input">
                                @Html.TextBoxFor(t => t.FullName)
                            </div>
                        </div>
                        <div class="search-group">
                            <label class="search-label">@Html.DisplayNameFor(t => t.Email)</label>
                            <div class="span2 search-input">
                                @Html.TextBoxFor(t => t.Email)
                            </div>
                        </div>
                    </div>

                    <div class="control-group none-border">
                        <div class="search-group">
                            <label class="search-label">@Html.DisplayNameFor(t => t.Phone)</label>
                            <div class="span2 search-input">
                                @Html.TextBoxFor(t => t.Phone)
                            </div>
                        </div>
                        <div class="search-group">
                            <label class="search-label">@Html.DisplayNameFor(t => t.Enabled)</label>
                            <div class="span2 search-input">
                                @Html.DropDownListFor(t => t.Enabled, Model.EnabledItems)
                            </div>
                        </div>
                    </div>

                    <div class="control-group none-border">
                        <div class="search-group">
                            <label class="search-label">@Html.DisplayNameFor(t => t.StartTime)</label>
                            <div class="span2 search-input">
                                @Html.DatePickerFor(t => t.StartTime)
                            </div>
                        </div>
                        <div class="search-group">
                            <label class="search-label">@Html.DisplayNameFor(t => t.EndTime)</label>
                            <div class="span2 search-input">
                                @Html.DatePickerFor(t => t.EndTime)
                            </div>
                        </div>
                    </div>

                    <div class="form-actions form-operate text-right ">
                        <button type="button" class="btn btn-danger" onclick="ClearForm($('.search-form'));">
                            <span class="icon-bullhorn"></span>清空
                        </button>
                        <button type="button" class="btn btn-success" onclick="Search()">
                            <span class="icon-search"></span>搜索
                        </button>
                        @if (createButton != null)
                        {
                            <button type="button" class="btn btn-primary" onclick="Create()">
                                <span class="@createButton.Icon"></span>@createButton.Text
                            </button>
                        }
                    </div>

                </form>

            </div>
        </div>

        <!--列表-->
        <div class="widget-box">
            <div class="widget-title">
                <span class="icon"><i class="icon-th"></i></span>
                <h5>用户列表</h5>
            </div>
            <div class="widget-content nopadding">
                <table class="table table-bordered data-table">
                    <thead>
                        <tr>
                            <th width="5%">序号</th>
                            <th width="12%" class="th-hover">用户名</th>
                            <th width="12%" class="th-hover">电子邮件</th>
                            <th width="10%">姓名</th>
                            <th width="7%">电话号码</th>
                            <th width="10%" class="th-hover">是否激活</th>
                            <th width="14%" class="th-hover">注册时间</th>
                            <th width="14%" class="th-hover">最后登陆时间</th>
                            <th width="16%">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>

    </div>
</div>

@section scripts{
    @Scripts.Render("~/bundles/jqueryui")
    <script type="text/javascript">
        var oTable = null;

        $(function () {
            var actionUrl = "@Url.Action("List")?rand=" + Math.random();
            var aoColumns = [
                    { "sName": "SortId", "bSortable": false },
                    { "sName": "LoginName", "bSortable": true },
                    { "sName": "Email", "bSortable": true },
                    { "sName": "FullName", "bSortable": false },
                    { "sName": "Phone", "bSortable": false },
                    { "sName": "Enabled", "bSortable": true },
                    { "sName": "RegisterTime", "bSortable": true },
                    { "sName": "LastLoginTime", "bSortable": true },
                    {
                        "sName": "Id",
                        "bSearchable": false,
                        "bSortable": false,
                        "fnRender": function (oObj) {
                            var btnArray = "";
                            @if (changePwdButton != null)
                            {
                                <text>btnArray += '<button type="submit" class="btn btn-inverse btn-normal" title="@changePwdButton.Text" onclick="ChangePwd(' + oObj.aData[oObj.aData.length - 1] + ')"><span class="@changePwdButton.Icon"></span></button>'</text>
                            }
                            @if (editButton != null)
                            {
                                <text>btnArray += '<button type="submit" class="btn btn-primary btn-normal" title="@editButton.Text" onclick="Edit(' + oObj.aData[oObj.aData.length - 1] + ')"><span class="@editButton.Icon"></span></button>'</text>
                            }
                            @if (deleteButton != null)
                            {
                                <text>btnArray += '<button type="submit" class="btn btn-danger btn-normal" title="@deleteButton.Text"  onclick="Delete(' + oObj.aData[oObj.aData.length - 1] + ')"><span class="@deleteButton.Icon"></span></button>'</text>
                            }
                            return btnArray;
                        }
                    }
            ];
            //初始化表格
            oTable = InitDatatables($(".data-table"), actionUrl, aoColumns, oTable);
        });

                //查询
                function Search() {
                    var filterdata = $(".search-form").serialize();
                    var actionUrl = "@Url.Action("List")?rand=" + Math.random() + "&" + filterdata;
                    SearchRecord(actionUrl, oTable);
                }

                //新增
                function Create() {
                    var actionUrl = "@Url.Action("Create")";
                    location.href = actionUrl;
                }

                //编辑
                function Edit(id) {
                    var actionUrl = "@Url.Action("Edit")" + "/" + id;
                    location.href = actionUrl;
                }

                //修改密码
                function ChangePwd(id) {
                    var actionUrl = "@Url.Action("ChangePwd")" + "/" + id;
                    location.href = actionUrl;
                }

                //删除
                function Delete(id) {
                    var actionUrl = "@Url.Action("Delete")";
                    var param = { Id: id }
                    DeleteRecord(actionUrl, param, oTable);
                }
    </script>
}
